package com.cater.utils;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.cater.sys.entity.Dictionarydata;
import com.cater.sys.service.impl.DictionarydataServiceImpl;

/**
 * 字典工具类
 * @author sd
 *
 */
@Component
public class DictionaryUtil {
	
	@Autowired
	private DictionarydataServiceImpl dictionarydataService;//数据字典

	public void setDictionarydataService(DictionarydataServiceImpl dictionarydataService) {
		this.dictionarydataService = dictionarydataService;
	}
	
	public static DictionaryUtil DictionaryUtil;
	@PostConstruct     //关键二   通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
	    public void init() {  
		DictionaryUtil = this;  
		DictionaryUtil.dictionarydataService = this.dictionarydataService;   // 初使化时将已静态化的testService实例化
	    }  
	public static String getLible(String key,String type){
		Dictionarydata ss =DictionaryUtil.dictionarydataService.getByTypeValue(key, type);
		return ss.getValueName();
	}
	
	public static JSONObject getLible(String type){
		JSONObject json = new JSONObject();
		json.put("dictionary", DictionaryUtil.dictionarydataService.getDataByType(type));
		return json;
	}
}
